package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysMechanism;
import com.ruoyi.system.service.ISysMechanismService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * 机构信息管理Controller
 * 
 * @author ruoyi
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/mechanism")
public class SysMechanismController extends BaseController
{
    @Autowired
    private ISysMechanismService sysMechanismService;

    /**
     * 查询机构信息管理列表
     */
    @RequiresPermissions("system:mechanism:list")
    @GetMapping("/list")
    public AjaxResult list(SysMechanism sysMechanism)
    {
        List<SysMechanism> list = sysMechanismService.selectSysMechanismList(sysMechanism);
        return AjaxResult.success(list);
    }

    /**
     * 导出机构信息管理列表
     */
    @RequiresPermissions("system:mechanism:export")
    @Log(title = "机构信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMechanism sysMechanism)
    {
        List<SysMechanism> list = sysMechanismService.selectSysMechanismList(sysMechanism);
        ExcelUtil<SysMechanism> util = new ExcelUtil<SysMechanism>(SysMechanism.class);
        util.exportExcel(response, list, "机构信息管理数据");
    }

    /**
     * 获取机构信息管理详细信息
     */
    @RequiresPermissions("system:mechanism:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysMechanismService.selectSysMechanismById(id));
    }

    /**
     * 新增机构信息管理
     */
    @RequiresPermissions("system:mechanism:add")
    @Log(title = "机构信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMechanism sysMechanism)
    {
        return toAjax(sysMechanismService.insertSysMechanism(sysMechanism));
    }

    /**
     * 修改机构信息管理
     */
    @RequiresPermissions("system:mechanism:edit")
    @Log(title = "机构信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMechanism sysMechanism)
    {
        return toAjax(sysMechanismService.updateSysMechanism(sysMechanism));
    }

    /**
     * 删除机构信息管理
     */
    @RequiresPermissions("system:mechanism:remove")
    @Log(title = "机构信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysMechanismService.deleteSysMechanismByIds(ids));
    }

    @GetMapping("/selectMaxId")
    public Long selectMaxId(){
        return sysMechanismService.selectMaxId();
    }
}
